// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        YellowButton:cc.Node
    },

    // LIFE-CYCLE CALLBACKS:
    
    onLoad: function () {
        var self = this;
        var NewMatched;
        self.YellowButton.on (cc.Node.EventType.TOUCH_START,function(event) {
            var CurrentLocation = self.node.parent.getComponent('CanvasScript').CurrentLocation;
            if(!self.node.parent.getChildByName('Button'+CurrentLocation).getComponent('ButtonScript').Matched){
                var CurrentNumber = self.node.getChildByTag(-1).getComponent(cc.Label).string;
                self.node.parent.getComponent('CanvasScript').CurrentNumber = Number(CurrentNumber);
                self.node.parent.getChildByName('Button'+CurrentLocation).getChildByName('Label'+CurrentLocation).getComponent(cc.Label).string = CurrentNumber;
                self.node.parent.getChildByName('Button'+CurrentLocation).getComponent('ButtonScript').CurrentNumber = Number(CurrentNumber);
                if(CurrentNumber >= self.node.parent.getChildByName('Button'+CurrentLocation).getComponent('ButtonScript').LowerBound &&
                CurrentNumber <= self.node.parent.getChildByName('Button'+CurrentLocation).getComponent('ButtonScript').UpperBound){    //按键值在当前数位的有效范围之内
                    self.node.parent.getComponent('CanvasScript').Match(self.node.parent, CurrentLocation, Number(CurrentNumber));
                }
            }
        }, self.node);
    },

    start () {

    },

//    update (dt) {},
});
